package com.molamil.perilla {
	/**
	 * @author martindyrby
	 */

	import org.molamil.acto.app.AbstractApp;
	import org.molamil.acto.pages.PagesEvent;
	
	public class PerillaActoController {
		
		private var _app:AbstractApp;
		
		public function PerillaActoController(app:AbstractApp) {
			_app = app;
		}
		
		public function init():void {
			
			Perilla.init(this);
			
			_app.addEventListener(PagesEvent.PAGE_ON, pageDisplayHandler);
			_app.addEventListener(PagesEvent.BLOCK_ON, pageDisplayHandler);
			_app.addEventListener(PagesEvent.PAGE_CLEAR, pageClearHandler);
			_app.addEventListener(PagesEvent.BLOCK_CLEAR, pageClearHandler);
		}
		
		
		private function pageDisplayHandler(event : PagesEvent) : void {
			if(event.context.props.hasOwnProperty('noFlashControl')) return;
			Perilla.register(event.sourceId, event.targetObject);
		}
		
		private function pageClearHandler(event : PagesEvent) : void {
			if(event.context.props.hasOwnProperty('noFlashControl')) return;
			Perilla.unregister(event.sourceId);
		}
	}
}
